$(window).load(function () {
	var sbWidth = $(window).width();

	function configIframe() {

		/*给首页产品分类宽度值*/
		var pro_hdW = 0;
		$(".h_products .pro_hd ul").find("li").each(function () {
			pro_hdW += $(this).width() + 2;
		});
		$(".h_products .pro_hd ul").width(pro_hdW);
	}


	configIframe();

	/*窗口改变事件*/
	window.onresize = function () {
		/*window.location.reload();*/
		configIframe();

	}


});

//全局Function事件
//表单校验事件
function formCheck() {
	if (!$("#mobile").val().match(/^(((13[0-9]{1})|(14[0-9]{1})|(15[0-9]{1})|(16[0-9]{1})|(17[0-9]{1})|(18[0-9]{1})|(19[0-9]{1}))+\d{8})$/)) {
		$("#mobile").focus();
		$.message({
			message: '联系电话格式不正确！',
			type: 'warning'
		});
		return false;
	}

	if (!$("#email").val().match(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/)) {
		$("#email").focus();
		$.message({
			message: '常用邮箱格式不正确！',
			type: 'warning'
		});
		return false;
	}

	var json = {
		'userName': $("#userName").val(),
		'telphone': $("#mobile").val(),
		'email': $("#email").val(),
		'message': $("#content").val(),
		'pageFrom': location.href,
	};

	$.ajax({
		type: 'post', // post
		url: 'http://www.luckyblank.cn/prod-api/business/msg/forOuter',
		dataType: "json",
		contentType: "application/json; charset=utf-8",
		data: JSON.stringify(json),
		success: function (result) {
			if (result.code == 200) {
				//提交成功提示
				$.message({
					message: '感谢您的提交，稍后我们将及时安排专员联系您！',
					type: 'success'
				});
			}

		},
		error: function (error) {
			console.log("error:" + error);
		}
	});

	return false;
}

//全局相关新闻
let news = [{
		title: "Rand to Participate in Upcoming Investor Conference",
		desc: "DAVIDSON, N.C., May 14, 2024 (GLOBE NEWSWIRE) - Ingersoll Rand Inc., (NYSE: IR) a global provider of mission-critical flow creation and industrial solutions, announced that Vik Kini, chief financial officer, and Matthew Fort, vice president, Investor Relations and Corporate FP&A, will participate in a fireside chat at the Wolfe 17th Annual Global Transportation and Industrials Conferen...",
		link: "https://investors.irco.com/news/news-details/2024/Ingersoll-Rand-to-Participate-in-Upcoming-Investor-Conference-ab83eccc2/default.aspx",
		wholedate: "2024-05-14",
		monthdate: "2024-05",
		daydate: "14",
		cover: "https://qny.luckyblank.cn/atf/banner/banner_news.jpg"
	},
	{
		title: "Ingersoll Rand Successfully Completes $3,300 Million Senior Unsecured Bond Offering and New $2,600 Million Senior Unsecured Revolving Credit Facility, Upgraded One Notch by All Three Rating Agencies",
		desc: "Ingersoll Rand Inc. (NYSE: IR) (the “Company” or “Ingersoll Rand”), a global provider of mission-critical flow creation and industrial solutions, announced today that the Company has successfully completed a series of transactions issuing Senior Unsecured Bonds and putting in place a new Senior Unsecured Revolving Credit Facility. The Company raised $3,276 million in net proceeds from the ...",
		link: "https://www.atlascopco.com.cn/cn/corp/news/%20industrial-gas-equipment-China-RD%26production-base-officially-settled-Suzhou",
		wholedate: "2024-05-10",
		monthdate: "2024-05",
		daydate: "06",
		cover: ""
	},
	{
		title: "Ingersoll Rand Leads $19M Financing Round for Inkbit to Advance Multi-Functional Additive Manufacturing",
		desc: "Medford, Mass. – May 6, 2024 – Inkbit ™ , a pioneer in advanced additive manufacturing solutions, announced today the closing of a $19M financing round led by Ingersoll Rand (NYSE: IR), with participation from Future Labs Capital, GC Ventures America, iGlobe Partners, Ocado, Phoenix Venture Partners, Stratasys, Zeon Ventures, and other private investors. As part of the transaction, Jason W...",
		link: "https://investors.irco.com/news/news-details/2024/Ingersoll-Rand-Successfully-Completes-3300-Million-Senior-Unsecured-Bond-Offering-and-New-2600-Million-Senior-Unsecured-Revolving-Credit-Facility-Upgraded-One-Notch-by-All-Three-Rating-Agencies/default.aspx",
		wholedate: "2024-05-06",
		monthdate: "2024-05",
		daydate: "06",
		cover: ""
	},
	{
		title: "Ingersoll Rand Reports Record First Quarter 2024 Revenue, Adjusted EBITDA, and Adjusted EPS Performance",
		desc: "Raises Total Company Adjusted EBITDA and Adjusted EPS Guidance First Quarter 2024 Highlights (All comparisons against the first quarter of 2023 unless otherwise noted.) Strong performance driven by its competitive differentiator - Ingersoll Rand Execution Excellence (IRX): First quarter orders of $1,707 million, down 4%, or down 7% organic On a two-year stack, up 5%, or up 1% organic Repor...",
		link: "https://investors.irco.com/news/news-details/2024/Ingersoll-Rand-Reports-Record-First-Quarter-2024-Revenue-Adjusted-EBITDA-and-Adjusted-EPS-Performance/default.aspx",
		wholedate: "2024-05-02",
		monthdate: "2024-05",
		daydate: "02",
		cover: ""
	},
]


//全局子产品列表
let secondTypeList = [{
		id: 'GSXPB',
		dataPtype: 'GSXPB',
		href: 'javascript:;',
		src: 'https://qny.luckyblank.cn/atf/product/gsxpb.png',
		text: '干式旋片泵',
		desc: '采用成熟的螺杆技术、专业高效的密封设计，提升真空泵可靠性，适用于食品、航空航天、橡塑、精细化工、制药、工业、光伏、锂电池、碳氢化合物清洗、干燥等应用领域。',
		tags: [],
		recomendRank: 1
	},
	{
		id: 'ZSB',
		dataPtype: 'ZSB',
		href: 'javascript:;',
		src: 'https://qny.luckyblank.cn/atf/product/zsb.png',
		text: '爪式泵',
		desc: '爪式泵',
		tags: [],
		recomendRank: 1
	},
	{
		id: 'CLFJ',
		dataPtype: 'CLFJ',
		href: 'javascript:;',
		src: 'https://qny.luckyblank.cn/atf/product/clfj.png',
		text: '侧流风机',
		desc: '侧流风机',
		tags: [],
		recomendRank: 1
	},
	{
		id: 'YSXPB',
		dataPtype: 'YSXPB',
		href: 'javascript:;',
		src: 'https://qny.luckyblank.cn/atf/product/ysxpb.png',
		text: '油式旋片泵',
		desc: '油式旋片泵',
		tags: [],
		recomendRank: 1
	},
	{
		id: 'LCB',
		dataPtype: 'LCB',
		href: 'javascript:;',
		src: 'https://qny.luckyblank.cn/atf/product/lcb.png',
		text: '罗茨泵',
		desc: '罗茨泵',
		tags: [],
		recomendRank: 1
	},
	{
		id: 'GSLGB',
		dataPtype: 'GSLGB',
		href: '/zh-cn/product/dry-screw-pump',
		src: 'https://qny.luckyblank.cn/atf/product/gslgb.png',
		text: '干式螺杆泵',
		desc: '干式螺杆泵',
		tags: [{
			text: '推荐',
			type: 'danger'
		}],
		recomendRank: 3
	},
	{
		id: 'YSLGB',
		dataPtype: 'YSLGB',
		href: '/zh-cn/product/oil-screw-pump',
		src: 'https://qny.luckyblank.cn/atf/product/yslgb2.png',
		text: '油式螺杆泵',
		desc: '油式螺杆泵',
		tags: [{
			text: '推荐',
			type: 'danger'
		}],
		recomendRank: 2
	}
]

/** 按照推荐等级排序 推荐等级越高拍的越靠前 **/
secondTypeList = secondTypeList.sort((a, b) => b.recomendRank - a.recomendRank);


/**
 * 初始化首页新闻
 */
function initIndexNews() {


}

/**
 * 初始化产品右侧的新闻
 */
function initProductNews() {
	$("ul.product-news").html('')

	news.forEach((item) => {
		let temp =
			`<li>
				<a href="${item.link}" title="${item.title}" target="_blank">${item.title}</a>
			</li>`;

		$("ul.product-news").append(temp);

	})


}

/**
 * 初始化产品中心
 */
function initProductCenter() {
	$(".product-center-list").html('')
	secondTypeList.forEach((item) => {
		let temp =
			`<li>
					<div> 
						<a href="${item.href}" class="pro_img">
							<img src="${item.src}" alt="${item.text}">
							<i class="iblock"></i>
						</a>
						<p>
							<a class="product-desc" href="${item.href}">${item.text}</a>
						</p>
					</div>
				</li>`;

		$("ul.product-center-list").append(temp);
	})
}

/**
 * 初始化产品详情中产品中心
 */
function initProductCenterInDetail() {
	$(".product-center-list").html('')
	$('.secondTypeList').each((index, element) => {
		let ptype = $(element).data("ptype");
		console.log("ptype " + ptype)
		let tempStr = "";
		secondTypeList.filter((it => it.dataPtype == ptype)).forEach((item) => {
			tempStr = tempStr + `<a class="product-desc" href="${item.href}">${item.text}</a>`;
		})
		$(element).append(tempStr);
	})
}

/**
 * 排除自身的其他4产品
 * @param {*} myId 
 */
function initRecommendPros(myId) {

	let recommendList = secondTypeList.filter((item) => item.id !== myId);
	let recommendFour = [];
	//随机筛选出4只产品
	let maxIndex = recommendList.length - 1;
	let tempRadomArr = [];
	recommendList.forEach(() => {
		let radomIndex = Math.round(Math.random() * maxIndex);
		if (tempRadomArr.indexOf(radomIndex) == -1 && tempRadomArr.length < 4) {
			tempRadomArr.push(radomIndex);
			recommendFour.push(recommendList[radomIndex]);
		}
	});

	console.log("ddd " + JSON.stringify(recommendFour))

	$('ul.xgcp').html('');

	recommendFour.forEach(secondType => {

		let recommendTemplate =
			`<li>
					<div> 
						<a href="${secondType.href}" class="pro_img">
						<img src="${secondType.src}"  alt="${secondType.text}">
						</a>
						<p>
						<a href="${secondType.href}">${secondType.text}</a>
						</p>
					</div>
				</li>`;

		$('ul.xgcp').append(recommendTemplate);
	});
}

//页面加载完及执行
$(function () {

	/*ATF VACUUM TECHNOLOGY PTE.LTD.点击事件*/
	var menu_flag = 0;
	$('.btn-menu').click(function (event) {
		if (menu_flag == 0) {
			$(this).toggleClass('active');
			$('.navigation').slideToggle(300);
			menu_flag = 1;
		} else {
			$(this).toggleClass('active');
			$('.navigation').slideToggle(300);
			menu_flag = 0;
		}
		event.stopPropagation();
	});

	/*导航搜索框点击事件*/
	var search_flag = 0;
	$('.h_search_wrap').click(function (event) {
		if (search_flag == 0) {
			$('.h_search').slideDown();
			$(this).addClass('h_search_wrap2');
			search_flag = 1;
		} else {
			$('.h_search').slideUp();
			$(this).removeClass('h_search_wrap2');
			search_flag = 0;
		}
	});

	/*产品目录收缩*/
	$(".menu_li>a").hover(function () {
		$(".menu_li>ul").hide();
		$(this).next('ul').show();
	}, function () {

	});

	/*联系方式tab切换*/
	$(".contact .tags_title .one").hover(function () {
		$(this).removeClass('ron');
		$(".contact .tags_title .two").addClass('ron');
		$(".contact .content2").hide();
		$(".contact .content1").show();
	}, function () {

	});
	$(".contact .tags_title .two").hover(function () {
		$(this).removeClass('ron');
		$(".contact .tags_title .one").addClass('ron');
		$(".contact .content1").hide();
		$(".contact .content2").show();
	}, function () {

	});

	/*产品目录收缩*/
	$(".pro_mulu>ul>li").on('click', function () {
		$(this).find('p').stop(true).toggleClass('on');
		$(this).children('div').stop(true).slideToggle(300);
	});

	/*手机端产品目录展开*/
	var menu_tit_flag = 0;
	$('.ny_content .content_left .c_tlt').on('click', function () {
		if (matchMedia('only screen and (max-width:767px)').matches) {

			if (menu_tit_flag == 0) {
				$('.ny_content .content_left .pro_mulu').stop(true).slideToggle(300);
				$(this).children('em').html('点击收起 -');
				menu_tit_flag = 1;
			} else {
				$('.ny_content .content_left .pro_mulu').stop(true).slideToggle(300);
				$(this).children('em').html('点击展开+');
				menu_tit_flag = 0;
			}
		}
	});

	/* -----QQ 侧边悬浮 ---- */
	$(".suspension .a").bind("mouseenter", function () {
		var _this = $(this);
		var s = $(".suspension");
		var isService = _this.hasClass("a-service");
		var isServicePhone = _this.hasClass("a-service-phone");
		var isQrcode = _this.hasClass("a-qrcode");
		if (isService) {
			s.find(".d-service").show().siblings(".d").hide();
		}
		if (isServicePhone) {
			s.find(".d-service-phone").show().siblings(".d").hide();
		}
		if (isQrcode) {
			s.find(".d-qrcode").show().siblings(".d").hide();
		}
	});
	$(".suspension, .suspension .a-top").bind("mouseleave", function () {
		$(".suspension").find(".d").hide();
	});
	$(".suspension .a-top").bind("mouseenter", function () {
		$(".suspension").find(".d").hide();
	});
	$(".suspension .a-top").bind("click", ".suspension .a-top", function () {
		$("html,body").animate({
			scrollTop: 0
		});
	});

	// 切换语言
	$(".lang").change(function(){
		$('.lang-flag').attr('data-flag',$(this).val());
		let _href = location.href;
		if($(this).val() === 'zh-cn'){
			_href = _href.replace('en-us', $(this).val());
		}
		if($(this).val() === 'en-us'){
			_href = _href.replace('zh-cn', $(this).val());
		}
		window.location.href = _href;
	})
	


})


$(window).scroll(function () {
	var st = $(document).scrollTop();
	var $top = $(".suspension .a-top");
	if (st > 400) {
		$top.css({
			display: 'block'
		});
	} else {
		if ($top.is(":visible")) {
			$top.hide();
		}
	}
});